<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<title>数据验证Demo</title>
</head>

<body>
	<script type="text/javascript" src="Validate.js"></script>
	<script>
		var rule = {
			'name': '@姓名|require|chinese!$0必须是中文',
			'idcard': '@身份证号码|require|idcard',
			'type': '@类型|require|in:0,1',
			'qq': '@QQ号码|require|number',
			'email': '@电子邮箱|require|email',
			'password': '@密码|require|len:6,10',
			'password2': '@确认密码|confirm:password',
			'like':'@喜欢的数字|require|in:0,1,2,3,4,5,6'
		}, data = {
			'name': 'nullfeng',
			'idcard': '50023619951105256a',
			'type': 0,
			'qq': '',
			'email': 'nullfeng(at)163.com',
			'password': '123123',
			'password2': '456456',
			'like': '8'
		};
		/**
		 * 验证全部的错误
		 */
		var result = Validate.check(rule,data,true);
		console.log(result);
		//output:
		/*{
			email:"电子邮箱格式不正确"
			idcard:"身份证号码格式不正确"
			like:"喜欢的数字只能取0,1,2,3,4,5,6"
			name:"姓名只能是中文"
			password2:"确认密码不一致"
			qq:"QQ号码不能为空"
		}*/
		/**
		 * 验证单个错误
		 */
		result = Validate.check('@昵称|chinese','nullfeng');
		console.log(result);
		// output: 昵称只能是中文
		/**
		 * 异步验证
		 */
		/*Validate.rule('unique',function(v){
			console.log(v);
			setTimeout(()=>{
				if(v=='nullfeng'){
					this.fail();
				}else{
					this.success();
				}
			},1000);
		},'$0已存在！');
		result = Validate.check2(rule,data,true);
		result.then(function(){
			console.log("成功");
		}).catch(function(msg){
			console.log(msg);
		});*/
	</script>
</body>

</html>